home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / tests / bit / RCS / bit.c,v < prev   
Encoding:
Text File  |  1988-06-20  |  3.7 KB  |  180 lines

  1. head     1.1;
  2. access   ;
  3. symbols  ;
  4. locks    ; strict;
  5. comment  @ * @;
  6.  
  7.  
  8. 1.1
  9. date     88.06.19.17.53.41;  author ouster;  state Exp;
  10. branches ;
  11. next     ;
  12.  
  13.  
  14. desc
  15. @@
  16.  
  17.  
  18.  
  19. 1.1
  20. log
  21. @Initial revision
  22. @
  23. text
  24. @/* 
  25.  * bit.c --
  26.  *
  27.  *    This file contains a program that exercises the bit
  28.  *    library procedures.  Invoke it with no parameters;  it
  29.  *    will print messages on stderr for any problems it detects
  30.  *    with the string procedures.
  31.  *
  32.  * Copyright 1988 Regents of the University of California
  33.  * Permission to use, copy, modify, and distribute this
  34.  * software and its documentation for any purpose and without
  35.  * fee is hereby granted, provided that the above copyright
  36.  * notice appear in all copies.  The University of California
  37.  * makes no representations about the suitability of this
  38.  * software for any purpose.  It is provided "as is" without
  39.  * express or implied warranty.
  40.  */
  41.  
  42. #ifndef lint
  43. static char rcsid[] = "$Header: bstring.c,v 1.1 88/04/25 21:41:10 ouster Exp $ SPRITE (Berkeley)";
  44. #endif not lint
  45.  
  46. #include <stdio.h>
  47. #include <bit.h>
  48.  
  49. #define error(string) \
  50.     fprintf(stderr, string); \
  51.     exit(1);
  52.  
  53. /*
  54.  * Utility procedure to compare two arrays for equality.
  55.  */
  56.  
  57. void
  58. check(a1, a2, size, msg)
  59.     register int *a1;        /* First array. */
  60.     register int *a2;        /* Second array. */
  61.     int size;            /* No. of bits in each array. */
  62.     char *msg;            /* Message to print if there's a mismatch. */
  63. {
  64.     int i;
  65.  
  66.     for (i = 0; i < size; i++) {
  67.     if (Bit_Set(i, a1)) {
  68.         if (Bit_Set(i, a2)) {
  69.         continue;
  70.         }
  71.     } else {
  72.         if (Bit_Clear(i, a2)) {
  73.         continue;
  74.         }
  75.     }
  76.     error(msg);
  77.     }
  78. }
  79.  
  80. main()
  81. {
  82.     int *a1, *a2, *a3, i;
  83.     static int test1[] = {0xf0f0f0f0, 0xf0f0f0f0, 0xffff};
  84.     static int test2[] = {0x11111111, 0x88888888, 0x0000};
  85.     static int test3[] = {0x10101010, 0x80808080, 0x0000};
  86.     static int test4[] = {0xf1f1f1f1, 0xf8f8f8f8, 0xffff};
  87.  
  88.     /*
  89.      * Bit_Set, Bit_Clear, Bit_FindFirstSet
  90.      */
  91.  
  92.     Bit_Alloc(99, a1);
  93.     if (Bit_FindFirstSet(100, a1) != -1) {
  94.     error("Bit_FindFirstSet error 1\n");
  95.     }
  96.     Bit_Set(99, a1);
  97.     if (Bit_FindFirstSet(100, a1) != 99) {
  98.     error("Bit_FindFirstSet error 2\n");
  99.     }
  100.     Bit_Set(0, a1);
  101.     if (Bit_FindFirstSet(100, a1) != 0) {
  102.     error("Bit_FindFirstSet error 3\n");
  103.     }
  104.     Bit_Clear(0, a1);
  105.     if (Bit_FindFirstSet(100, a1) != 99) {
  106.     error("Bit_FindFirstSet error 4\n");
  107.     }
  108.     Bit_Clear(99, a1);
  109.     if (Bit_FindFirstSet(100, a1) != -1) {
  110.     error("Bit_FindFirstSet error 5\n");
  111.     }
  112.  
  113.     /*
  114.      * Bit_IsSet, Bit_IsClear
  115.      */
  116.  
  117.     Bit_Set(45, a1);
  118.     if (!Bit_IsSet(45, a1)) {
  119.     error("Bit_IsSet error 1\n");
  120.     }
  121.     if (Bit_IsClear(45, a1)) {
  122.     error("Bit_IsSet error 2\n");
  123.     }
  124.     if (Bit_IsSet(46, a1)) {
  125.     error("Bit_IsSet error 3\n");
  126.     }
  127.     if (!Bit_IsClear(46, a1)) {
  128.     error("Bit_IsSet error 4\n");
  129.     }
  130.     if (Bit_FindFirstSet(100, a1) != 45) {
  131.     error("Bit_IsSet error 5\n");
  132.     }
  133.  
  134.     /*
  135.      * Bit_FindFirstClear
  136.      */
  137.  
  138.     for (i = 0; i < 37; i++) {
  139.     Bit_Set(i, a1);
  140.     }
  141.     if (Bit_FindFirstClear(100, a1) != 37) {
  142.     error("Bit_FindFirstClear error 1\n");
  143.     }
  144.     Bit_Clear(36, a1);
  145.     if (Bit_FindFirstClear(100, a1) != 36) {
  146.     error("Bit_FindFirstClear error 2\n");
  147.     }
  148.  
  149.     /*
  150.      * Bit_AnySet, Bit_Zero
  151.      */
  152.  
  153.     if (!Bit_AnySet(100, a1)) {
  154.     error("Bit_AnySet error 1\n");
  155.     }
  156.     Bit_Zero(100, a1);
  157.     if (Bit_AnySet(100, a1)) {
  158.     error("Bit_AnySet error 2\n");
  159.     }
  160.  
  161.     /*
  162.      * Bit_Union, Bit_Intersect
  163.      */
  164.  
  165.     Bit_Intersect(72, test1, test2, a1);
  166.     check(a1, test3, 72, "Bit_Intersect error 1\n");
  167.     Bit_Union(72, test1, test2, a1);
  168.     check(a1, test4, 72, "Bit_Union error 1\n");
  169.  
  170.     /*
  171.      * Bit_Copy
  172.      */
  173.  
  174.     Bit_Copy(65, test1, a1);
  175.     check(test1, a1, 65, "Bit_Copy error 1\n");
  176.  
  177.     exit(0);
  178. }
  179. @
  180.